package com.haiertvbic.tvnow.util;

import android.app.Activity;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;
import android.widget.Toast;

import com.haiertvbic.tvnow.R;

public class LocateToast {

	public static void locateToast(Activity context, int width, String content) {
		LayoutInflater inflater = LayoutInflater.from(context);
		View toastView = inflater.inflate(R.layout.toast_layout, null);
		TextView contentView = (TextView) toastView.findViewById(R.id.content);
		contentView.setLayoutParams(new LayoutParams(width,
				LayoutParams.WRAP_CONTENT));
		contentView.setText(content);

		int disWidth = context.getWindowManager().getDefaultDisplay()
				.getWidth();

		Toast toast = new Toast(context);
		toast.setView(toastView);
		toast.setGravity(Gravity.BOTTOM | Gravity.RIGHT,
				(disWidth / 8 - width / 2), 50);
		toast.setDuration(1);
		toast.show();

	}

	public static void showToast(int resultCode, Activity context) {
		switch (resultCode) {
		case 0:
			LocateToast.locateToast(context, 200, context.getResources()
					.getString(R.string.read_change_msg_failed));
			break;

		case 4004500:
			LocateToast.locateToast(context, 200, context.getResources()
					.getString(R.string.change_success));
			break;

		case 4004501:
			LocateToast.locateToast(context, 200, context.getResources()
					.getString(R.string.channel_non_existent));
			break;

		case 4004502:
			LocateToast.locateToast(context, 200, context.getResources()
					.getString(R.string.please_connect_crb));
			break;

		case 4004503:
			LocateToast.locateToast(context, 200, context.getResources()
					.getString(R.string.no_set_crb));
			break;

		case -2002:
			LocateToast.locateToast(context, 200, context.getResources()
					.getString(R.string.connect_break_off));
			break;
		default:
			break;
		}
	}

}
